package tech.aistar.corejava.day05.HomeWork.ShoppingCart;

/**
 * Created by 李雨昂 on 2019/7/21.
 */
public class Demo {

    //遍历输出商品的id与名称
    public static void demo0(Product[] product){
        for (int i = 0; i < product.length; i++) {
            System.out.println(product[i].getId()+","+product[i].getName());
        }
    }

    //输出显示商品价格超过某个价格的商品的名称
    public static void demo1(Product[] product ,double price){
        for(int i = 0;i < product.length;i++){
            if(product[i].getPrice() > price){
                System.out.println(product[i].getName().toString());
            }
        }
    }

    //按照商品价格从低到高，将商品重新排序
    public static void demo2(Product[] product){
        for (int i = 0; i < product.length; i++) {
            for (int j = 0; j <product.length - i -1 ; j++) {
                if(product[j].getPrice() > product[j+1].getPrice()){
                    Product arr = product[j + 1];
                    product[j+1] = product[j];
                    product[j] = arr;
                }
            }
        }
        for (int i = 0; i < product.length; i++) {
            System.out.println(product[i].toString());
        }
    }
}
